summaryrefslogtreecommitdiff
path: root/share/frontend/gallery-static/js/main.js
blob: aadc7e1562de538f95025eb93ad7c5cd5fe09b0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
$(function(){
  for (var i=0; i < imagedata.length; i++){
    var newDiv = document.createElement("div");
    var newImage = document.createElement("img");
    newImage.src = imagedata[i];
    newImage.className = "pb";
    newDiv.appendChild(newImage);
//    consider calling something like isotope add here...and ONLY APPENDING the image to the parent div once it has loaded
//    $(newImage).load(function(){
//    })
    $("#images").append(newDiv);
  }
});

$(function(){
  $("b").addClass("pulsate_and_grow");
  $(".sorting-options").click(function(){

  $(".sorting-options").click(function(){
    if ($(this).hasClass("pulsate_opacity")){
      $(this).removeClass("pulsate_opacity");
    }
    $(this).addClass("pulsate_opacity");

  });
  });
});


//ZeroClipboard.setMoviePath( 'http://asdf.us/swf/ZeroClipboard10.swf' );
//var clip = new ZeroClipboard.Client();
//clip.glue( 'd_clip_button' );


var Dump = {
  current_urls: [],
  pick: function ()
    {
    Dump.pickUrl( $(this).attr("src") )
    },
  pickUrl: function (url)
    {
    Dump.current_urls.push(url)
    Dump.load_rebus()
    },
  clear: function ()
    {
    $("#rebus").html("")
    $("#urlz").val("")
    Dump.current_urls = []
    window.localStorage.setItem('urls', "")
//    clip.setText("")
    },
  load_rebus: function(){
    var as_str = Dump.current_urls.join(" ")
    window.localStorage.setItem('urls', as_str)
//    $("#rebus").html("")
    $("#rebus").html(
        Dump.current_urls.map(
          function(url){ return $("<img>").attr("src", url)[0].outerHTML}
        ).join(" ")
    )
    $("#rebus").show()
    console.log(as_str)
    $("#urlz").val( as_str )
  },
  backspace: function ()
    {
      Dump.current_urls.pop()
      Dump.load_rebus()
    },
  reverse: function ()
    {
    Dump.current_urls.reverse()
    Dump.load_rebus()
    },
  showNewer: function()
    {
    },
  showOlder: function()
    {
    }
}

function applyTag(tagname){
  tag_regex = /&tag=[^&]*/;
  if (document.URL.match(tag_regex)){
    return document.URL.replace(tag_regex, "&tag="+tagname);
  }else if(document.URL.match(/\/$/)){
     return document.URL.replace(/\/$/, "?tag="+tagname);
  }
  else{
    return document.URL+"&tag="+tagname;
  }
}
var Main =
  {
  editing: false,
  kp: function (event)
    {
    switch (event.keyCode)
      {
      // BS
      case 8:
        if (! Main.editing) {
          event.stopPropagation()
          Dump.backspace()
        }
        return false
      // C
      case 67:
        if (! Main.editing)
          Dump.clear()
        break
      // R
      case 82:
        if (! Main.editing)
          Dump.reverse()
        break
      // ESC
      case 27:
      // H
      case 72:
        if (! Main.editing)
          $("#rebus").toggle()
        break
      // LEFT ARROW
      case 37:
        if (! Main.editing)
          Dump.showNewer()
        break
      // RIGHT ARROW
      case 39:
        if (! Main.editing)
          Dump.showOlder()
        break
      case 83:
        if (! Main.editing)
          window.sorter.shuffle()
        break
      }
      // S key
    return true
    },
  poll: function ()
    {
    },
  pollCallback: function ()
    {
    },
  init: function ()
    {
    //the rebus needs to preload dumps that are stored from localstorage
    if (window.localStorage.getItem('urls')){
      Dump.current_urls = window.localStorage.getItem('urls').split(" ")
    }else{
      Dump.current_urls = []
    }
    $(document).keydown(Main.kp)
    $("#urlz").focus(function(){ Main.editing = true })
    $("#urlz").blur(function(){ Main.editing = false })
    $("#clear").live("click", Dump.clear)
    $("#help").click(function(){ $("#keys").slideToggle() })
    $("#actions b").click(function(){ $("#sorting-optionsContainer").slideToggle() })
    $("#tags b").click(function(){ $("#tag-optionsContainer").slideToggle() })
    $(".tag-options").click(function(){document.location.href= applyTag(this.id)});
    $(".tag-clear").click(function(){ document.location.href = document.URL.replace(/&?tag=[^&]*/ ,"").replace(/\?$/,"")});
    $("div img").live("click", Dump.pick)
    Dump.load_rebus()
//    Dump.clear()
    }
  }




$(function(){
  //get params from the query string, and create
  //the back and newer buttons
  //taking into account name, tag and random
  var params = {
    name
  }
  Main.init()
})