/modules/mod_base/actions/action_base_mask.erl

https://code.google.com/p/zotonic/ · Erlang · 38 lines · 19 code · 3 blank · 16 comment · 0 complexity · 139f3150a85b26801a4bc3010415de69 MD5 · raw file

  1. %% @author Marc Worrell <marc@worrell.nl>
  2. %% @copyright 2010 Marc Worrell
  3. %% @doc Mask an element or the whole page with a busy indicator.
  4. %% Copyright 2010 Marc Worrell
  5. %%
  6. %% Licensed under the Apache License, Version 2.0 (the "License");
  7. %% you may not use this file except in compliance with the License.
  8. %% You may obtain a copy of the License at
  9. %%
  10. %% http://www.apache.org/licenses/LICENSE-2.0
  11. %%
  12. %% Unless required by applicable law or agreed to in writing, software
  13. %% distributed under the License is distributed on an "AS IS" BASIS,
  14. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. %% See the License for the specific language governing permissions and
  16. %% limitations under the License.
  17. -module(action_base_mask).
  18. -include("zotonic.hrl").
  19. -export([render_action/4]).
  20. render_action(_TriggerId, TargetId, Args, Context) ->
  21. Selector = case proplists:get_value(body, Args) of
  22. true -> "body";
  23. _ ->
  24. case z_render:css_selector(TargetId, Args) of
  25. [] -> "body";
  26. S -> S
  27. end
  28. end,
  29. Message = proplists:get_value(message, Args, ""),
  30. Delay = proplists:get_value(delay, Args, 0),
  31. Script = [ <<"try { ">>, z_render:render_css_selector(Selector) ,<<".mask('">>,
  32. z_utils:js_escape(Message), $',$,,
  33. z_convert:to_list(Delay),
  34. <<"); } catch (e) {};">>],
  35. {Script, Context}.